'use strict';
const moment = require('moment');
module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;
  const Contract = app.model.define('contract', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    type: {
      type: STRING,
    },
    state: {
      type: INTEGER,
    },
    money: {
      type: INTEGER,
    },
    payment: {
      type: STRING,
    },
    paid: {
      type: INTEGER,
    },
    starttime: {
      type: DATE,
    },
    endtime: {
      type: DATE,
    },
    paytime: {
      type: DATE,
    },
    info: {
      type: STRING,
    },
    duration: {
      type: INTEGER,
    },
    return: {
      type: INTEGER,
    },
    b_company_name: {
      type: STRING,
    },
    b_company_address: {
      type: STRING,
    },
    b_phone: {
      type: STRING,
    },
    b_fax: {
      type: STRING,
    },
    b_contact: {
      type: STRING,
    },
    b_signatory: {
      type: STRING,
    },
    s_company_name: {
      type: STRING,
    },
    s_company_address: {
      type: STRING,
    },
    s_phone: {
      type: STRING,
    },
    s_fax: {
      type: STRING,
    },
    s_contact: {
      type: STRING,
    },
    s_signatory: {
      type: STRING,
    },
    customer_id: {
      type: INTEGER,
    },
    examine_info: {
      type: STRING,
    },
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
    updated_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
  });
  Contract.associate = () => {
    Contract.belongsTo(app.model.Contract.Application, {
      foreignKey: 'application_id',
    });
    Contract.belongsTo(app.model.Customer.Customer, {
      foreignKey: 'customer_id',
    });
  };
  return Contract;
};
